home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / exedexes.c < prev    next >
C/C++ Source or Header  |  2000-01-12  |  6KB  |  180 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *exedexes_bg_scroll;
  15.  
  16. unsigned char *exedexes_nbg_yscroll;
  17. unsigned char *exedexes_nbg_xscroll;
  18.  
  19. #define TileMap(offs) (memory_region(REGION_GFX5)[offs])
  20. #define BackTileMap(offs) (memory_region(REGION_GFX5)[offs+0x4000])
  21.  
  22.  
  23. /***************************************************************************
  24.  
  25.   Convert the color PROMs into a more useable format.
  26.  
  27.   Exed Exes has three 256x4 palette PROMs (one per gun), three 256x4 lookup
  28.   table PROMs (one for characters, one for sprites, one for background tiles)
  29.   and one 256x4 sprite palette bank selector PROM.
  30.  
  31.   The palette PROMs are connected to the RGB output this way:
  32.  
  33.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  34.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  35.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  36.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  37.  
  38. ***************************************************************************/
  39. void exedexes_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  40. {
  41.     int i;
  42.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  43.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  44.  
  45.  
  46.     for (i = 0;i < Machine->drv->total_colors;i++)
  47.     {
  48.         int bit0,bit1,bit2,bit3;
  49.  
  50.  
  51.         bit0 = (color_prom[0] >> 0) & 0x01;
  52.         bit1 = (color_prom[0] >> 1) & 0x01;
  53.         bit2 = (color_prom[0] >> 2) & 0x01;
  54.         bit3 = (color_prom[0] >> 3) & 0x01;
  55.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  56.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  57.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  58.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  59.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  60.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  61.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  62.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  63.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  64.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  65.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  66.  
  67.         color_prom++;
  68.     }
  69.  
  70.     color_prom += 2*Machine->drv->total_colors;
  71.     /* color_prom now points to the beginning of the lookup table */
  72.  
  73.     /* characters use colors 192-207 */
  74.     for (i = 0;i < TOTAL_COLORS(0);i++)
  75.         COLOR(0,i) = (*color_prom++) + 192;
  76.  
  77.     /* 32x32 tiles use colors 0-15 */
  78.     for (i = 0;i < TOTAL_COLORS(1);i++)
  79.         COLOR(1,i) = (*color_prom++);
  80.  
  81.     /* 16x16 tiles use colors 64-79 */
  82.     for (i = 0;i < TOTAL_COLORS(2);i++)
  83.         COLOR(2,i) = (*color_prom++) + 64;
  84.  
  85.     /* sprites use colors 128-191 in four banks */
  86.     for (i = 0;i < TOTAL_COLORS(3);i++)
  87.     {
  88.         COLOR(3,i) = color_prom[0] + 128 + 16 * color_prom[256];
  89.         color_prom++;
  90.     }
  91. }
  92.  
  93.  
  94.  
  95. /***************************************************************************
  96.  
  97.   Draw the game screen in the given osd_bitmap.
  98.   Do NOT call osd_update_display() from this function, it will be called by
  99.   the main emulation engine.
  100.  
  101. ***************************************************************************/
  102. void exedexes_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  103. {
  104.     int offs,sx,sy;
  105.  
  106.  
  107. /* TODO: this is very slow, have to optimize it using a temporary bitmap */
  108.     /* draw the background graphics */
  109.     /* back layer */
  110.     for(sy = 0;sy <= 8;sy++)
  111.     {
  112.         for(sx = 0;sx < 8;sx++)
  113.         {
  114.                int xo,yo,tile;
  115.  
  116.  
  117.             xo = sx*32;
  118.             yo = ((exedexes_bg_scroll[1])<<8)+exedexes_bg_scroll[0] + sy*32;
  119.  
  120.             tile = ((yo & 0xe0) >> 5) + ((xo & 0xe0) >> 2) + ((yo & 0x3f00) >> 1);
  121.  
  122.             drawgfx(bitmap,Machine->gfx[1],
  123.                     BackTileMap(tile) & 0x3f,
  124.                     BackTileMap(tile+8*8),
  125.                     BackTileMap(tile) & 0x40,BackTileMap(tile) & 0x80,
  126.                     sy*32-(yo&0x1F),sx*32,
  127.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  128.         }
  129.     }
  130.  
  131.     /* front layer */
  132.     for(sy = 0;sy <= 16;sy++)
  133.     {
  134.         for(sx = 0;sx < 16;sx++)
  135.         {
  136.                int xo,yo,tile;
  137.  
  138.  
  139.             xo = ((exedexes_nbg_xscroll[1])<<8)+exedexes_nbg_xscroll[0] + sx*16;
  140.             yo = ((exedexes_nbg_yscroll[1])<<8)+exedexes_nbg_yscroll[0] + sy*16;
  141.  
  142.             tile = ((yo & 0xf0) >> 4) + (xo & 0xF0) + (yo & 0x700) + ((xo & 0x700) << 3);
  143.  
  144.             drawgfx(bitmap,Machine->gfx[2],
  145.                 TileMap(tile),
  146.                 0,
  147.                 0,0,
  148.                 sy*16-(yo&0xF),sx*16-(xo&0xF),
  149.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  150.         }
  151.     }
  152.  
  153.  
  154.     /* Draw the sprites. */
  155.     for (offs = spriteram_size - 32;offs >= 0;offs -= 32)
  156.     {
  157.         drawgfx(bitmap,Machine->gfx[3],
  158.                 spriteram[offs],
  159.                 spriteram[offs + 1] & 0x0f,
  160.                 spriteram[offs + 1] & 0x10, spriteram[offs + 1] & 0x20,
  161.                 spriteram[offs + 3] - 0x10 * (spriteram[offs + 1] & 0x80),spriteram[offs + 2],
  162.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  163.     }
  164.  
  165.  
  166.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  167.     for (offs = videoram_size - 1;offs >= 0;offs--)
  168.     {
  169.         sx = offs % 32;
  170.         sy = offs / 32;
  171.  
  172.         drawgfx(bitmap,Machine->gfx[0],
  173.                 videoram[offs] + 2 * (colorram[offs] & 0x80),
  174.                 colorram[offs] & 0x3f,
  175.                 0,0,
  176.                 8*sx,8*sy,
  177.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,207);
  178.     }
  179. }
  180.